<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    //计算圆的面积
    let pi = Math.PI.toFixed(2)
    function s(r) {
        // pi*r*r
        console.log(pi * Math.pow(r, 2));
    }
    s(10);
    //第二题
    let x = prompt('?')
    function fun2(x) {
        if (x >= 18) {
            alert('你可以浏览网站');
        } else {
            alert('看葫芦娃');
        }
    }
    fun2(x);
    //第三题
    function fun3(a, b) {
        if (a >= b) {
            let num = Math.round(Math.random() * (a - b) + b)
            console.log(num);
        } else {
            let num = Math.round(Math.random() * (b - a) + a)
            console.log(num);
        }
    }
    fun3(10, 20)

    //第四题

    function fun4() {
        switch (arguments.length) {
            case 0:
                console.log(Math.round(Math.random() * (10 - 1) + 1));
                break;
            case 1:
                console.log(Math.round(Math.random() * arguments[0]));
                break;
            case 2:
                if (arguments[0] > arguments[1]) {
                    console.log(Math.round(Math.random() * (arguments[0] - arguments[1]) + arguments[1]));
                } else {
                    console.log(Math.round(Math.random() * (arguments[1] - arguments[0]) + arguments[0]));
                }
        }
    }
    fun4(10, 1)

    //第五题
    function fun5(len, start, end) {
        len = len == undefined ? 5 : len;
        start = start == undefined ? 0 : start;
        end = end == undefined ? 100 : end;
        let Arr = [];
        function random(start, end) {
            return Math.floor(Math.random() * (end - start) + start)
        }
        switch (arguments.length) {
            case 0:
                for (let i = 0; i < len; i++) {
                    Arr.push(random(start, end))
                }
                console.log(Arr);
                break;
            case 1:
                for (let i = 0; i < len; i++) {
                    Arr.push(random(start, end))
                }
                console.log(Arr);
                break;
            case 2:
                for (let i = 0; i < len; i++) {
                    Arr.push(random(start, end))
                }
                console.log(Arr);
                break;
            case 3:
                for (let i = 0; i < len; i++) {
                    Arr.push(random(start, end))
                }
                console.log(Arr);
        }
    }
    fun5(8, 10)
    //第六题
    function fun6() {
        let Arr = Array.from(arguments);
        Arr.sort(function (a, b) {
            return b - a    // 降序
        })
        console.log([Arr[0], Arr[Arr.length - 1]]);
    }
    fun6(2, 4, 6, 9, 3)
    //let arr=[4,8,6,1,5,4,6]
    function fun6(arr) {
        console.log(`最大值为：${Math.max(...max)}`);
        console.log(`最小值为：${Math.min(...max)}`);
    }
    //第七题
    let arr1 = [1, 3, 6, 8]
    function fun7(arr, num) {
        let arr2 = []
        num = num == undefined ? 1 : num;
        for (let i = 0; i < arr.length; i++) {
            arr2[i] = arr1[i] * num
        }
        console.log(arr2)
    }
    fun7(arr1, 2)
    //第八题
    let stu = {
        name: '',
        className: '',
        mathScore: '',
        chiscore: '',
        engScore: ''
    };
    function fun8(xx) {
        xx.name = 'jay'
        xx.className = '计应8'
        xx.mathScore = 99
        xx.chiscore = 95
        xx.engScore = 93
    }
    fun8(stu)
    let nul = stu.mathScore + stu.chiscore + stu.engScore
    ping = (nul / 3).toFixed(2)
    console.log(`${stu.className}班 ${stu.name}，语文：${stu.chiscore}，数学：${stu.mathScore}，英语：${stu.engScore}，总分：${nul},平均分：${ping}。`);

    //第九题
    let arr2 = []
    for (let i = 1; i <= 100; i++) {
        arr2.push(i)
    }
    function fun9(arr, page, many) {
        //开始截取下标
        let star = (page - 1) * many
        //结束下标
        let end = star + many
        let newArr = arr.slice(star.end)
        console.log(newArr);
    }
    fun9(arr2,2,5)
</script>